package drawingObjects;

import java.awt.Graphics;
import java.awt.Point;

public class Oval extends DrawingObject {

	private Point anchorPoint;
	private Point startPoint;
	private Point endPoint;
	public Oval() {
		super();
		anchorPoint = new Point(0,0);
		startPoint = new Point(0,0);
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		if(endPoint != null && startPoint != endPoint){
			//System.out.println("anchor: "+anchorPoint.x+", "+anchorPoint.y+" start: "+startPoint.x+", "+startPoint.y+" end: "+endPoint.x+", "+endPoint.y);
			if(endPoint.x < anchorPoint.x){
				//System.out.println("adjust x positions");
				startPoint.x = new Integer(endPoint.x);
				endPoint.x = new Integer(anchorPoint.x);
			}
			if(endPoint.y < anchorPoint.y){
				//System.out.println("adjust y positions");
				startPoint.y = new Integer(endPoint.y);
				endPoint.y = new Integer(anchorPoint.y);
			}
			g.drawOval(startPoint.x, startPoint.y, endPoint.x - startPoint.x, endPoint.y - startPoint.y);
			
		}
	}

	@Override
	public void start(Point p) {
		startPoint = p;
		anchorPoint = new Point(p);
	}

	@Override
	public void step(Point p) {
		endPoint = p;
	}
	
	 public boolean commit() {
		 return  startPoint != null && endPoint != null;
	 }

}
